home *** CD-ROM | disk | FTP | other *** search
- /*
- * Windowing Library
- * Initialization routines
- */
-
- #include <stdlib.h>
- #include <string.h>
- #include <netdb.h>
- #include <sys/socket.h>
- #include <sys/types.h>
- #include <netinet/in.h>
- #include <arpa/inet.h>
-
- #include "winlib.h"
- #include "internal.h"
- #include "config.h"
-
- WINDOW *_main_win, *_menu_win, *_menu_area;
- PANEL *_main_pan, *_menu_pan, *_menu_area_pan;
- MENU *_menutree;
- void (*_keydispatch)(), (*_mousedispatch)();
- int _cur_title, _showing_menu, _cur_window, _xoffset, _sound_socket,
- _sound_init, _resizing_win, _resize_corner;
-
- /* Set keyboard callback routine */
- void Win_SetCallbackKEYBOARD(void *routine)
- {
- _keydispatch = (routine == NULL) ? NULL : routine;
- }
-
- /* Set mouse callback routine */
- void Win_SetCallbackMOUSE(void *routine)
- {
- _mousedispatch = (routine == NULL) ? NULL : routine;
- }
-
- /* Report back the current library version */
- char *Win_GetLibraryVersion(void)
- {
- return(WINLIB_VERSION);
- }
-
- int Win_GetOptions(void)
- {
- int x;
-
- x = 0;
-
- #ifdef DEBUG
- x |= OPT_DEBUG;
- #endif
-
- #ifdef MOUSE_COORD
- x |= OPT_MOUSECOORD;
- #endif
-
- #ifdef COLOR_SUPPORT
- x |= OPT_COLOR;
- #endif
-
- #ifdef SOUND_SUPPORT
- x |= OPT_SOUND;
- #endif
-
- #ifdef WAVFILE
- x |= OPT_WAVFILE;
- #endif
-
- #ifdef USE_DEV_AUDIO
- x |= OPT_USEDEVAUDIO;
- #endif
-
- if (_sound_init)
- x |= OPT_SOUNDINIT;
-
- return(x);
- }
-
- /* Initialize NCURSES code */
- void Win_InitializeNCURSES(void)
- {
- if (initscr() != NULL) {
- start_color();
- cbreak();
- noecho();
- nonl();
- scrollok(stdscr, FALSE);
- keypad(stdscr, TRUE);
- refresh();
- } else {
- printf("WinLIB: Cannot initialize ncurses library!\n");
- fflush(stdout);
- exit(0);
- }
- }
-
- /* Initialize GPM cruft. This is basic code, and was used in the standard
- GPM library and demo programs. */
- void Win_InitializeGPM(void)
- {
- Gpm_Connect conn;
-
- conn.eventMask = ~0;
- conn.defaultMask = ~GPM_HARD;
- conn.maxMod = ~0;
- conn.minMod = 0;
-
- if (Gpm_Open(&conn, 0) < 0) {
- printf("WinLIB: Cannot initialize GPM library! (First connect)\n");
- fflush(stdout);
- exit(0);
- }
-
- Gpm_Close();
-
- gpm_zerobased = 1;
- gpm_visiblepointer = 1;
-
- if (Gpm_Open(&conn, 0) < 0) {
- printf("WinLIB: Cannot initialize GPM library! (Second connect)\n");
- fflush(stdout);
- exit(0);
- }
-
- /* Don't forget to set the library handler! */
- gpm_handler = Win_LibHandler;
- }
-
- void Win_InitializeVARIABLES(void)
- {
- _has_menu = FALSE;
- _has_win = FALSE;
- _cur_title = 0;
- _cur_item = -1;
- _cur_window = 0;
- _xoffset = 0;
- _sound_init = 0;
- _moving_idx = -1;
- _resize_corner = 0;
- _showing_menu = FALSE;
- _changed = FALSE;
- _moving_win = FALSE;
- _resizing_win = FALSE;
- _keydispatch = NULL;
- _mousedispatch = NULL;
- _open_sound = NULL;
- _close_sound = NULL;
- _destroy_sound = NULL;
- _min_sound = NULL;
- _max_sound = NULL;
-
- _menutree = (MENU *) malloc(_menustruct_length());
- _menutree->prev = NULL;
- _menutree->next = NULL;
-
- _wintree = (WIN *) malloc(_winstruct_length());
- _wintree->prev = NULL;
- _wintree->next = NULL;
-
- _main_win = newwin(stdscr->_maxy, stdscr->_maxx + 1, 1, 0);
- _main_pan = new_panel(_main_win);
-
- scrollok(_main_win, TRUE);
- }
-
- int Win_Initialize(void)
- {
- Win_InitializeNCURSES();
- Win_InitializeGPM();
- Win_InitializeVARIABLES();
-
- return(TRUE);
- }
-
- int Win_InitializeSound(void)
- {
- struct protoent *p;
- struct sockaddr_in sin;
-
- bzero((char *) &sin, sizeof(sin));
- sin.sin_family = AF_INET;
- sin.sin_port = htons(8000);
- sin.sin_addr.s_addr = inet_addr(SOUND_ADDRESS);
-
- p = getprotobyname("tcp");
- if ((_sound_socket = socket(AF_INET, SOCK_STREAM, p->p_proto)) < 0)
- return(FALSE);
-
- if (connect(_sound_socket, (struct sockaddr *) &sin, sizeof(sin)) < 0)
- return(FALSE);
-
- tcdrain(_sound_socket);
-
- _sound_init = 1;
- return(TRUE);
- }
-
- void Win_Deinitialize(void)
- {
- Win_PlaySound(SOUND_EXIT);
- erase();
- refresh();
- endwin();
- }
-